package com.ems.controller.Invigilate.room;

import com.ems.pojo.Invigilate.room.TestRoom;
import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.user.User;
import com.ems.service.Invigilate.room.TestRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2020/2/18
 * @Description: 描述
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有ip跨域
@RequestMapping("/testRoom")
public class TestRoomController {
    @Autowired
    @Qualifier("testRoomService")
    private TestRoomService testRoomService;

    //添加考场
    @RequestMapping("/addTestRoom")
    @ResponseBody
    public ResultData addTestRoom(@RequestBody TestRoom testRoom, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
        testRoom.setId(user.getId());
        testRoomService.addTestRoom(testRoom);
        return RetunResult.AssemblyData();
    }

    //删除考场
    @RequestMapping("/deleteTestRoom")
    @ResponseBody
    public ResultData deleteTestRoom(@RequestBody List<TestRoom> list){
        testRoomService.deleteTestRoom(list);
        return RetunResult.AssemblyData();
    }

    //编辑考场
    @RequestMapping("/updateTestRoom")
    @ResponseBody
    public ResultData updateTestRoom(@RequestBody TestRoom testRoom){
        testRoomService.updateTestRoom(testRoom);
        return RetunResult.AssemblyData();
    }

    //查询考场
    @RequestMapping("/selectTestRoom")
    @ResponseBody
    public ResultData selectTestRoom(@RequestBody RequestData requestData,HttpServletRequest request){
        ReturnPageResult.setPageHelperInfo(requestData);
        User user = (User) request.getSession().getAttribute("user");
        List<TestRoom> list = testRoomService.selectTestRoom(requestData.getMap(),user);
        return ReturnPageResult.AssemblyData(list);
    }

    //根据id查询考场
    @RequestMapping("/selectTestRoomById")
    @ResponseBody
    public ResultData selectTestRoomById(@RequestBody TestRoom testRoom){
        TestRoom testRoom1 = testRoomService.selectTestRoomById(testRoom);
        return RetunResult.AssemblyData(testRoom1);
    }


    //查询申请进入考场的考生信息
    @RequestMapping("/selectUnRoomUser")
    @ResponseBody
    public ResultData selectUnRoomUser(@RequestBody RequestData requestData,HttpServletRequest request){
        ReturnPageResult.setPageHelperInfo(requestData);
        User user = (User) request.getSession().getAttribute("user");
        List<TestRoom> list = testRoomService.selectUnRoomUser(requestData.getMap(),user);
        return ReturnPageResult.AssemblyData(list);
    }

}
